package com.maotai.llzhou.register;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.client.config.RequestConfig;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.maotai.llzhou.bean.CustomName;
import com.maotai.llzhou.bean.MaotaiString;
import com.maotai.llzhou.bean.MaotaiWebCookie;
import com.maotai.llzhou.service.MaotaiService;
import com.maotai.llzhou.util.HttpClientUtilNew;
import com.maotai.llzhou.util.IPFactory;

/**
 */
public class MaotaiRegisterCheckThread extends Thread {
	private MaotaiService maotaiService;
	private Map<String, Object> zhanghao;
	private String ipAndPort;
	private MaotaiWebCookie mwc;
	

	public MaotaiRegisterCheckThread(MaotaiService maotaiService,
			Map<String, Object> zhanghao, String ipAndPort, MaotaiWebCookie mwc) {
		super();
		this.maotaiService = maotaiService;
		this.zhanghao = zhanghao;
		this.ipAndPort = ipAndPort;
		this.mwc = mwc;
	}

	public MaotaiWebCookie getMwc() {
		return mwc;
	}

	public void setMwc(MaotaiWebCookie mwc) {
		this.mwc = mwc;
	}

	public String getIpAndPort() {
		return ipAndPort;
	}

	public void setIpAndPort(String ipAndPort) {
		this.ipAndPort = ipAndPort;
	}

	public MaotaiService getMaotaiService() {
		return maotaiService;
	}

	public void setMaotaiService(MaotaiService maotaiService) {
		this.maotaiService = maotaiService;
	}

	public Map<String, Object> getZhanghao() {
		return zhanghao;
	}

	public void setZhanghao(Map<String, Object> zhanghao) {
		this.zhanghao = zhanghao;
	}

	@Override
	public void run() {
		try {
			HttpClientUtilNew hcu = HttpClientUtilNew.getInstance();
			if (zhanghao.get("auth") == null || "".equals(zhanghao.get("auth"))) {
				zhanghao.put("loginstatus", "0");
				maotaiService.updateZhanghaoLoginStatus(zhanghao);
				zhanghao.put("checkstatus", "0");
				maotaiService.updateZhanghaoCheckStatus(zhanghao);
				return;
			}
			
			// 增加代理
			// String name = CustomName.getName();
			// String chars = "abcdefghijklmnopqrstuvwxyz";
			// System.out.println(chars.charAt((int)(Math.random() * 26)));
			Map<String, Object> personName = maotaiService.getPersonName();
			// String name =
			// personName.get("name")+""+chars.charAt((int)(Math.random() *
			// 26));//加上一个随机字母
			String name = personName.get("name") + "";// 加上一个随机字母
			RequestConfig config = IPFactory.getKdRequestConfig(ipAndPort);
			// 增加新增发票功能
			if (zhanghao.get("invoiceId") == null || "".equals(zhanghao.get("invoiceId"))) {
				// 查询发票
				mwc = hcu.sendHttpGetProxy(MaotaiString.INVOICE_QUERY_URL_NEW,
						mwc, config, MaotaiString.INVOICE_REFERER);
				System.out.println(zhanghao.get("code") + " 查询得发票信息：" + mwc.getContent());
				// {"data":[{"isSupport":null,"list":[{"accountId":3586409,"bankAccount":"","contactAddress":null,"contactPerson":null,"contactPhone":null,"createPerson":"migration program","createTime":"2017-12-11 16:39:05","def1":null,"def10":null,"def11":null,"def12":null,"def13":null,"def14":null,"def15":null,"def16":null,"def17":null,"def18":null,"def19":null,"def2":null,"def20":null,"def21":null,"def22":null,"def23":null,"def24":null,"def25":null,"def3":null,"def4":null,"def5":null,"def6":null,"def7":null,"def8":null,"def9":null,"dr":0,"id":461141,"invoiceContent":null,"invoiceContentType":1,"invoiceTaxType":1,"invoiceTitle":"鍛ㄤ寒浜?,"invoiceTitleType":1,"invoiceType":0,"isDefault":2,"openBank":"","orderBy":null,"orderByDesc":null,"orgName":"鍛ㄤ寒浜?,"registerAddress":"","registerPhone":"","sendType":null,"sqlFilters":null,"taxCode":"","tenantId":1,"updatePerson":"migration program","updateTime":"2018-06-24 14:31:07"}],"memberId":3586409,"shopId":null,"shopInvoice":null,"sign":null}],"resultCode":0,"resultMsg":"success"}
				if(mwc==null || mwc.getContent()==null||mwc.getContent().contains("login")){
					zhanghao.put("loginstatus", "0");
					maotaiService.updateZhanghaoLoginStatus(zhanghao);
					zhanghao.put("checkstatus", "0");
					maotaiService.updateZhanghaoCheckStatus(zhanghao);
					return;
				}
				if (mwc.getContent() != null && !"".equals(mwc.getContent())) {
					JSONObject jObject2 = JSONObject.parseObject(mwc
							.getContent());
					JSONArray data2 = jObject2.getJSONArray("data");
					JSONArray data3 =((JSONObject) data2.get(0)).getJSONArray("list");
					if (data3 == null || data3.size() == 0) {
						System.out.println("账号没有发票信息--");
						// 新增发票信息
						zhanghao = addInvoiceId(maotaiService, zhanghao, hcu, mwc,
								config, name);
						if (zhanghao!=null) {
							System.out.println(zhanghao.get("code")+ "---新增发票成功");
						}
					} else {
						// 新增功能，把发票id同步到数据库
						JSONObject obj = (JSONObject) (((JSONObject) data2
								.get(0)).getJSONArray("list").get(0));
						String accountId = obj.getString("accountId");
						String invoiceId = obj.getString("id");
						String invoiceTitle = obj.getString("invoiceTitle");
						String orgName = obj.getString("orgName");
						String createPerson = obj.getString("createPerson");
						String createTime = obj.getString("createTime");
						String updatePerson = obj.getString("updatePerson");
						String updateTime = obj.getString("updateTime");
						String invoicetext = obj.toString();
						zhanghao.put("invoiceId", invoiceId);
						zhanghao.put("accountId", accountId);
						zhanghao.put("id", invoiceId);
						zhanghao.put("invoiceTitle", invoiceTitle);
						zhanghao.put("orgName", orgName);
						zhanghao.put("createPerson", createPerson);
						zhanghao.put("createTime", createTime);
						zhanghao.put("updatePerson", updatePerson);
						zhanghao.put("updateTime", updateTime);
						zhanghao.put("invoicetext", invoicetext);
						zhanghao.put("invoiceId", invoiceId);
						zhanghao.put("accountId", accountId);
						
						maotaiService.updateZhanghaoInvoiceId(zhanghao);
						maotaiService.insertZhanghaoInvoice(zhanghao);
					}
				}
			}
			
	        
			if (zhanghao.get("addressId") == null || "".equals(zhanghao.get("addressId"))) {
				// 查询地址
				mwc = hcu.sendHttpGetProxy(MaotaiString.ADDRESS_QUERY_URL_NEW, mwc,
						config, MaotaiString.ADDRESS_REFERER);
				// {"data":[{"accountId":3586409,"address":"天禄大道1号翠屏城73栋805室","addressAlias":"","areaCode":"320115000000","areaName":"江宁区","cityCode":"320100000000","cityName":"南京市","createPerson":"nickboowen","createTime":"2018-06-27 10:17:38","def1":null,"def10":null,"def11":null,"def12":null,"def13":null,"def14":null,"def15":null,"def16":null,"def17":null,"def18":null,"def19":null,"def2":null,"def20":null,"def21":null,"def22":null,"def23":null,"def24":null,"def25":null,"def3":null,"def4":null,"def5":null,"def6":null,"def7":null,"def8":null,"def9":null,"defaultStatus":1,"deliveryEmail":"","deliveryMobile":"13372007847","deliveryName":"周亮亮","deliveryPhone":null,"dr":0,"id":"1179370534174015495","latitude":null,"longitude":null,"orderBy":null,"orderByDesc":null,"postcode":null,"provinceCode":"320000000000","provinceName":"江苏省","sqlFilters":null,"streetCode":null,"streetName":"","tenantId":1,"updatePerson":"nickboowen","updateTime":"2018-06-27 10:17:38"}],"resultCode":0,"resultMsg":"success"}
				System.out.println(zhanghao.get("code") + " 查询得地址信息："
						+ mwc.getContent());
				if (mwc.getContent() != null && !"".equals(mwc.getContent())) {
					JSONObject jObject2 = JSONObject.parseObject(mwc
							.getContent());
					JSONArray data2 = jObject2.getJSONArray("data");
	
					if (data2 == null || data2.size() == 0) {
						// 新增收货地址
						zhanghao = addAddress(maotaiService, zhanghao, hcu, mwc,
								config, name);
						if (zhanghao==null) {
							System.out.println(zhanghao.get("code")+ "---新增收货地址成功");
						} else {
							zhanghao.put("checkstatus", "0");
							maotaiService.updateZhanghaoCheckStatus(zhanghao);
						}
					} else {
		
						if (data2 != null && data2.size() > 0) {
							for (int i = 0; i < data2.size(); i++) {
								JSONObject dataObject = data2.getJSONObject(i);
								String accountId = dataObject.getString("accountId");
								String address = dataObject.getString("address");
								String areaCode = dataObject.getString("areaCode");
								String areaName = dataObject.getString("areaName");
								String cityCode = dataObject.getString("cityCode");
								String cityName = dataObject.getString("cityName");
								String provinceCode = dataObject.getString("provinceCode");
								String provinceName = dataObject.getString("provinceName");
								String createPerson = dataObject.getString("createPerson");
								String createTime = dataObject.getString("createTime");
								String deliveryMobile = dataObject.getString("deliveryMobile");
								String deliveryName = dataObject.getString("deliveryName");
								String id = dataObject.getString("id");
								zhanghao.put("accountId", accountId);
								zhanghao.put("address", address);
								zhanghao.put("areaCode", areaCode);
								zhanghao.put("areaName", areaName);
								zhanghao.put("cityCode", cityCode);
								zhanghao.put("cityName", cityName);
								zhanghao.put("provinceCode", provinceCode);
								zhanghao.put("provinceName", provinceName);
								zhanghao.put("createPerson", createPerson);
								zhanghao.put("createTime", createTime);
								zhanghao.put("deliveryMobile", deliveryMobile);
								zhanghao.put("deliveryName", deliveryName);
								zhanghao.put("id", id);
								zhanghao.put("addressId", id);
								maotaiService.updateZhanghaoAddressId(zhanghao);
								maotaiService.insertZhanghaoAddress(zhanghao);
							}
						}
					}
				}
			}
			zhanghao.put("checkstatus", "1");
			maotaiService.updateZhanghaoCheckStatus(zhanghao);
			MaotaiRegisterYuYueThread myyt = new MaotaiRegisterYuYueThread(maotaiService, zhanghao, ipAndPort,mwc);
			myyt.start();
			
		} catch (Exception e) {
			e.printStackTrace();
			try {
				zhanghao.put("checkstatus", "0");
				maotaiService.updateZhanghaoCheckStatus(zhanghao);
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		}
	}

	private Map<String, Object> addInvoiceId(MaotaiService maotaiService,
			Map<String, Object> zhanghao, HttpClientUtilNew hcu,
			MaotaiWebCookie mwc, RequestConfig config, String name)
			throws Exception {
		// 新增发票
		Map<String, String> orderMap = new HashMap<String, String>();
		orderMap.put("invoiceTitleType", "1");
		orderMap.put("invoiceType", "2");
		orderMap.put("invoiceTaxType", "1");
		orderMap.put("invoiceTitle", name);
		orderMap.put("name", "");
		orderMap.put("invoiceContent", "1");
		orderMap.put("taxCode", "");
		orderMap.put("openBank", "");
		orderMap.put("bankAccount", "");
		orderMap.put("registerAddress", "");
		orderMap.put("registerPhone", "");
		orderMap.put("isDefault", "1");
		mwc = hcu.sendHttpPostProxy(MaotaiString.INVOICE_ADD_URL_NEW, mwc,
				orderMap, config, MaotaiString.INVOICE_REFERER);
		System.out.println(zhanghao.get("code") + " 提交得发票信息："
				+ mwc.getContent());
		// {"data":null,"resultCode":0,"resultMsg":"success"}
//		System.out.println(mwc.getContent());
//		if (mwc.getContent().contains("success")) {
			// 查询发票
			mwc = hcu.sendHttpGetProxy(MaotaiString.INVOICE_QUERY_URL_NEW, mwc,
					config, MaotaiString.INVOICE_REFERER);
			System.out.println(zhanghao.get("code") + " 查询得发票信息："
					+ mwc.getContent());
			// {"data":[{"isSupport":null,"list":[{"accountId":3586409,"bankAccount":"","contactAddress":null,"contactPerson":null,"contactPhone":null,"createPerson":"migration program","createTime":"2017-12-11 16:39:05","def1":null,"def10":null,"def11":null,"def12":null,"def13":null,"def14":null,"def15":null,"def16":null,"def17":null,"def18":null,"def19":null,"def2":null,"def20":null,"def21":null,"def22":null,"def23":null,"def24":null,"def25":null,"def3":null,"def4":null,"def5":null,"def6":null,"def7":null,"def8":null,"def9":null,"dr":0,"id":461141,"invoiceContent":null,"invoiceContentType":1,"invoiceTaxType":1,"invoiceTitle":"鍛ㄤ寒浜?,"invoiceTitleType":1,"invoiceType":0,"isDefault":2,"openBank":"","orderBy":null,"orderByDesc":null,"orgName":"鍛ㄤ寒浜?,"registerAddress":"","registerPhone":"","sendType":null,"sqlFilters":null,"taxCode":"","tenantId":1,"updatePerson":"migration program","updateTime":"2018-06-24 14:31:07"}],"memberId":3586409,"shopId":null,"shopInvoice":null,"sign":null}],"resultCode":0,"resultMsg":"success"}
			if (mwc.getContent() != null && !"".equals(mwc.getContent())) {
				JSONObject jObject2 = JSONObject.parseObject(mwc.getContent());
				JSONArray data2 = jObject2.getJSONArray("data");

				// 新增功能，把发票id同步到数据库
				JSONObject obj = (JSONObject) (((JSONObject) data2.get(0))
						.getJSONArray("list").get(0));
				String accountId = obj.getString("accountId");
				String invoiceId = obj.getString("id");
				String invoiceTitle = obj.getString("invoiceTitle");
				String orgName = obj.getString("orgName");
				String createPerson = obj.getString("createPerson");
				String createTime = obj.getString("createTime");
				String updatePerson = obj.getString("updatePerson");
				String updateTime = obj.getString("updateTime");
				String invoicetext = obj.toString();
				zhanghao.put("invoiceId", invoiceId);
				zhanghao.put("accountId", accountId);
				zhanghao.put("id", invoiceId);
				zhanghao.put("invoiceTitle", invoiceTitle);
				zhanghao.put("orgName", orgName);
				zhanghao.put("createPerson", createPerson);
				zhanghao.put("createTime", createTime);
				zhanghao.put("updatePerson", updatePerson);
				zhanghao.put("updateTime", updateTime);
				zhanghao.put("invoicetext", invoicetext);
				maotaiService.updateZhanghaoInvoiceId(zhanghao);
				maotaiService.insertZhanghaoInvoice(zhanghao);
				
				
				return zhanghao;
			}
//		}
		return zhanghao;
	}
	private Map<String, Object> addAddress(MaotaiService maotaiService,
			Map<String, Object> zhanghao, HttpClientUtilNew hcu,
			MaotaiWebCookie mwc, RequestConfig config, String name)
			throws Exception {
		Map<String, String> addressMap = new HashMap<String, String>();
		String telphone = zhanghao.get("phone") + "";
		String addresss = "";
		// 从数据库中获取省市区
//		Map<String, Object> countryMap = maotaiService.getCountryRandomMY();
		
		Map<String, Object> countryMap = maotaiService.getCountryRandom();
		String provinceid = countryMap.get("provinceid") + "";
		String provincename = countryMap.get("provincename") + "";
		String cityid = countryMap.get("cityid") + "";
		String cityname = countryMap.get("cityname") + "";
		String areaid = countryMap.get("areaid") + "";
		String areaname = countryMap.get("areaname") + "";
		System.out.println(provincename + cityname + areaname + addresss);

		// 加省是没有用的，需要修改数据库改江苏为江苏省，上海为上海市
		JSONObject addrObj = new JSONObject();
		// 从数据库中查询是不是有这个地址了，有的话重新获取
//		String addressname = "";
//		while (true) {
//			addrObj = hcu.getAddress(cityname + areaname);
//			addressname = addrObj.getString("name");
//			Map<String, String> map = new HashMap<String, String>();
//			map.put("addressname", addressname);
//			List<Map<String, Object>> list = maotaiService
//					.getAddressByName(map);
//			if (list != null && list.size() > 0) {
//
//			} else {
//				break;
//			}
//		}

//		int lou = CustomName.getRandomGuiZe();
//		
//		if("静安区".equals(areaname)){
//			addresss = addrObj.getString("address") + "贵"+addressname;
////					+ CustomName.getRandomGuiZe() + "栋" + + lou + "0"
////					+ CustomName.getNum1() + "室";
//		}else{
//			addresss = addrObj.getString("address") + addressname;
////					+ CustomName.getRandomGuiZe() + "栋" + + lou + "0"
////					+ CustomName.getNum1() + "室";
//		}
//		
//		addresss = addresss.replace(provincename, "");
//		addresss = addresss.replace(cityname, "");
//		addresss = addresss.replace(areaname, "");
		int guize = CustomName.getRandomGuiZe();
//		Map<String,Object> roadName = maotaiService.getRoadName();
//		Map<String,Object> companyName = maotaiService.getCompanyName();
//		Map<String,Object> dianpuName = maotaiService.getDianpuName();
//		Map<String,Object> xiaoquName = maotaiService.getXiaoquName();
		if(guize==1){
			addresss += CustomName.getRoad()+"路"+CustomName.getNum()+"号"+CustomName.getRoad()+"公司"+CustomName.getRandomGuiZe()+"楼"+CustomName.getNum()+"室";
		}else if(guize==2){
			addresss += CustomName.getRoad()+"路"+CustomName.getRoad()+CustomName.getNum()+"号";
		}else if(guize==3){
			addresss += CustomName.getRoad()+"路"+CustomName.getRoad()+CustomName.getNum3()+"栋"+CustomName.getRandomGuiZe()+"楼"+CustomName.getNum()+"室";
		}else if(guize==4){
			addresss += CustomName.getRoad()+"路"+CustomName.getNum()+"号"+CustomName.getRoad()+"-"+CustomName.getNum();
		}else if(guize==5){
			//addresss += CustomName.getRoad()+""+CustomName.getNum()+"号"+CustomName.getRoad();
			addresss += CustomName.getRoad()+"路"+CustomName.getNum()+"号"+""+CustomName.getRoad()+CustomName.getNum3()+"栋"+CustomName.getNum()+"室";
		}
//		addresss = addrObj.getString("address") + addressname;
		addressMap.put("deliveryName", name);
		addressMap.put("address", addresss);
		addressMap.put("deliveryMobile", telphone);
		addressMap.put("deliveryEmail", "");
		addressMap.put("addressAlias", "");
		addressMap.put("provinceCode", provinceid);
		addressMap.put("cityCode", cityid);
		addressMap.put("areaCode", areaid);
		addressMap.put("defaultStatus", "1");
		mwc = hcu.sendHttpPostProxy(MaotaiString.ADDRESS_ADD_URL_NEW, mwc,
				addressMap, config, MaotaiString.ADDRESS_REFERER);
		// {"data":null,"resultCode":0,"resultMsg":"success"}
		System.out.println(zhanghao.get("code") + " 提交地址信息："
				+ mwc.getContent());
//		System.out.println(mwc.getContent());
//		if (mwc.getContent().contains("success")) {
			// 查询地址
			mwc = hcu.sendHttpGetProxy(MaotaiString.ADDRESS_QUERY_URL_NEW, mwc,
					config, MaotaiString.ADDRESS_REFERER);
			System.out.println(zhanghao.get("code") + " 查询得地址信息："
					+ mwc.getContent());
			if (mwc.getContent() != null && !"".equals(mwc.getContent())) {
				JSONObject jObject2 = JSONObject.parseObject(mwc.getContent());
				JSONArray data2 = jObject2.getJSONArray("data");

				// 新增功能，把发票id同步到数据库
				if (data2 != null && data2.size() > 0) {
					for (int i = 0; i < data2.size(); i++) {
						JSONObject dataObject = data2.getJSONObject(i);
						String accountId = dataObject.getString("accountId");
						String address = dataObject.getString("address");
						String areaCode = dataObject.getString("areaCode");
						String areaName = dataObject.getString("areaName");
						String cityCode = dataObject.getString("cityCode");
						String cityName = dataObject.getString("cityName");
						String provinceCode = dataObject
								.getString("provinceCode");
						String provinceName = dataObject
								.getString("provinceName");
						String createPerson = dataObject
								.getString("createPerson");
						String createTime = dataObject.getString("createTime");
						String deliveryMobile = dataObject
								.getString("deliveryMobile");
						String deliveryName = dataObject
								.getString("deliveryName");
						String id = dataObject.getString("id");
						zhanghao.put("accountId", accountId);
						zhanghao.put("address", address);
						zhanghao.put("areaCode", areaCode);
						zhanghao.put("areaName", areaName);
						zhanghao.put("cityCode", cityCode);
						zhanghao.put("cityName", cityName);
						zhanghao.put("provinceCode", provinceCode);
						zhanghao.put("provinceName", provinceName);
						zhanghao.put("createPerson", createPerson);
						zhanghao.put("createTime", createTime);
						zhanghao.put("deliveryMobile", deliveryMobile);
						zhanghao.put("deliveryName", deliveryName);
						zhanghao.put("id", id);
						zhanghao.put("addressId", id);
						maotaiService.updateZhanghaoAddressId(zhanghao);
						maotaiService.insertZhanghaoAddress(zhanghao);
					}
				}
				return zhanghao;
			}
//		}
		return zhanghao;
	}
	private Map<String, Object> addAddress2(MaotaiService maotaiService,
			Map<String, Object> zhanghao, HttpClientUtilNew hcu,
			MaotaiWebCookie mwc, RequestConfig config, String name)
			throws Exception {
		Map<String, String> addressMap = new HashMap<String, String>();
		String telphone = zhanghao.get("phone") + "";
		String addresss = "";
		// 从数据库中获取省市区
//		Map<String, Object> countryMap = maotaiService.getCountryRandomMY();
		
		Map<String, Object> countryMap = maotaiService.getCountryRandom();
		String provinceid = countryMap.get("provinceid") + "";
		String provincename = countryMap.get("provincename") + "";
		String cityid = countryMap.get("cityid") + "";
		String cityname = countryMap.get("cityname") + "";
		String areaid = countryMap.get("areaid") + "";
		String areaname = countryMap.get("areaname") + "";
		System.out.println(provincename + cityname + areaname + addresss);

		// 加省是没有用的，需要修改数据库改江苏为江苏省，上海为上海市
		JSONObject addrObj = new JSONObject();
		// 从数据库中查询是不是有这个地址了，有的话重新获取
		String addressname = "";
		while (true) {
			addrObj = hcu.getAddress(cityname + areaname);
			addressname = addrObj.getString("name");
			Map<String, String> map = new HashMap<String, String>();
			map.put("addressname", addressname);
			List<Map<String, Object>> list = maotaiService
					.getAddressByName(map);
			if (list != null && list.size() > 0) {

			} else {
				break;
			}
		}

		int lou = CustomName.getRandomGuiZe();
		
		if("静安区".equals(areaname)){
			addresss = addrObj.getString("address") + "贵"+addressname;
//					+ CustomName.getRandomGuiZe() + "栋" + + lou + "0"
//					+ CustomName.getNum1() + "室";
		}else{
			addresss = addrObj.getString("address") + addressname;
//					+ CustomName.getRandomGuiZe() + "栋" + + lou + "0"
//					+ CustomName.getNum1() + "室";
		}
		
		addresss = addresss.replace(provincename, "");
		addresss = addresss.replace(cityname, "");
		addresss = addresss.replace(areaname, "");
//		addresss = addrObj.getString("address") + addressname;
		addressMap.put("deliveryName", name);
		addressMap.put("address", addresss);
		addressMap.put("deliveryMobile", telphone);
		addressMap.put("deliveryEmail", "");
		addressMap.put("addressAlias", "");
		addressMap.put("provinceCode", provinceid);
		addressMap.put("cityCode", cityid);
		addressMap.put("areaCode", areaid);
		addressMap.put("defaultStatus", "1");
		mwc = hcu.sendHttpPostProxy(MaotaiString.ADDRESS_ADD_URL_NEW, mwc,
				addressMap, config, MaotaiString.ADDRESS_REFERER);
		// {"data":null,"resultCode":0,"resultMsg":"success"}
		System.out.println(zhanghao.get("code") + " 提交地址信息："
				+ mwc.getContent());
//		System.out.println(mwc.getContent());
//		if (mwc.getContent().contains("success")) {
			// 查询地址
			mwc = hcu.sendHttpGetProxy(MaotaiString.ADDRESS_QUERY_URL_NEW, mwc,
					config, MaotaiString.ADDRESS_REFERER);
			System.out.println(zhanghao.get("code") + " 查询得地址信息："
					+ mwc.getContent());
			if (mwc.getContent() != null && !"".equals(mwc.getContent())) {
				JSONObject jObject2 = JSONObject.parseObject(mwc.getContent());
				JSONArray data2 = jObject2.getJSONArray("data");

				// 新增功能，把发票id同步到数据库
				if (data2 != null && data2.size() > 0) {
					for (int i = 0; i < data2.size(); i++) {
						JSONObject dataObject = data2.getJSONObject(i);
						String accountId = dataObject.getString("accountId");
						String address = dataObject.getString("address");
						String areaCode = dataObject.getString("areaCode");
						String areaName = dataObject.getString("areaName");
						String cityCode = dataObject.getString("cityCode");
						String cityName = dataObject.getString("cityName");
						String provinceCode = dataObject
								.getString("provinceCode");
						String provinceName = dataObject
								.getString("provinceName");
						String createPerson = dataObject
								.getString("createPerson");
						String createTime = dataObject.getString("createTime");
						String deliveryMobile = dataObject
								.getString("deliveryMobile");
						String deliveryName = dataObject
								.getString("deliveryName");
						String id = dataObject.getString("id");
						zhanghao.put("accountId", accountId);
						zhanghao.put("address", address);
						zhanghao.put("areaCode", areaCode);
						zhanghao.put("areaName", areaName);
						zhanghao.put("cityCode", cityCode);
						zhanghao.put("cityName", cityName);
						zhanghao.put("provinceCode", provinceCode);
						zhanghao.put("provinceName", provinceName);
						zhanghao.put("createPerson", createPerson);
						zhanghao.put("createTime", createTime);
						zhanghao.put("deliveryMobile", deliveryMobile);
						zhanghao.put("deliveryName", deliveryName);
						zhanghao.put("id", id);
						zhanghao.put("addressId", id);
						maotaiService.updateZhanghaoAddressId(zhanghao);
						maotaiService.insertZhanghaoAddress(zhanghao);
					}
				}
				return zhanghao;
			}
//		}
		return zhanghao;
	}

}
